<?php
/**
 * ClassName: CardCateService
 * Description:
 * @Author 周昌
 * @Create 2023/11/16 10:42
 */

namespace service\admin;


use model\CardCateModel;
use model\CardModel;
use service\BaseService;

class CardCateService extends BaseService
{
    protected static $model='model\CardCateModel';
    public static $card_cate_type=[0=>'普通卡',1=>'贵宾卡'];
    public static $use_limit=[0=>'诊疗',1=>'不限'];

    //会员卡分类类型select选择
    public static function cardCateTypeSelect()
    {
        static $cardCate_type_select=[];
        if(empty($cardCate_type_select)){
            foreach (self::$card_cate_type as $k=>$v){
                $row=[];
                $row['id']=$k;
                $row['name']=$v;
                $cardCate_type_select[]=$row;
            }
            array_unshift($cardCate_type_select,['id'=>'','name'=>'-----请选择-----']);
        }
        return $cardCate_type_select;
    }
    //会员卡使用限制select选择
    public static function cardCateUseLimitSelect()
    {
        static $cardCate_userLimit_select=[];
        if(empty($cardCate_userLimit_select)){
            foreach (self::$use_limit as $k=>$v){
                $row=[];
                $row['id']=$k;
                $row['name']=$v;
                $cardCate_userLimit_select[]=$row;
            }
            array_unshift($cardCate_userLimit_select,['id'=>'','name'=>'-----请选择-----']);
        }
        return $cardCate_userLimit_select;
    }
    //根据card_id 获取卡分类名称
    public static function getCateName($card_id)
    {
        $card_cate_id=CardModel::getValue(['id'=>$card_id],'card_cate_id');
        return self::$model::getValue(['id'=>$card_cate_id],'name');

    }

    //列表数据
    public static function getAjaxData($where)
    {
        $table = self::$model::order('id desc');
        return self::tableJsonData($table, $where, function ($data){
            $data['type_name'] = self::$card_cate_type[$data['type']];
            $data['use_limt_name'] = self::$use_limit[$data['use_limit']];
            $data['hospital_name'] = $data['hospital_id']?HospitalService::getNameByKey($data['hospital_id'],''):'';
            return $data;
        });
    }

}